# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 15:16:19 2013

@author: han
"""
import os
import time
import shutil
import sys, stat
import math
from os.path import exists, join
import os.path
from os import pathsep

if __name__ == '__main__':
#    print sys.argv
    local_path = sys.argv[1]
    usnob1_rawinputfile = local_path + sys.argv[2]
if not sys.argv[1:]:
    sys.argv += ["/home/han/tmp_pool/", "usno_temp_r1.txt"]

local_path = sys.argv[1]
usnob1_rawinputfile = local_path + sys.argv[2]
#print usnob1_rawinputfile
usnob1_rawinputdata = open(usnob1_rawinputfile)


outputfile= local_path + "tmp_"+ sys.argv[2]
g = open(outputfile,'w')

while True:
    line = usnob1_rawinputdata.readline()
    if not line: 
        break
#        print line
#    line_nospace = line.replaceAll( "\\s+ ", "|")
#    line_nospace = ",".join(line.split())
    else:
        if line[0] != "#":
            usnoid = line[0:12].strip()
            tychoid = line[13:25].strip()
            RAdeg = float(line[26:36].strip())
            DEdeg = float(line[36:46].strip())
            pmRA = int(line[62:68].strip())
            pmDE = int(line[69:75].strip())
            b1mag = line[97:102].strip()
            if b1mag == '---' :
                b1mag = 0
            else:
                b1mag = float(b1mag)
            b2mag = line[159:164].strip()
            if b2mag == '---' :
                b2mag = 0
            else:
                b2mag = float(b2mag)
            r1mag = line[128:133].strip()
            if r1mag == '---' :
                r1mag = 0
            else:
                r1mag = float(r1mag)
            r2mag = line[190:195].strip()
            if r2mag == '---' :
                r2mag = 0
            else:
                r2mag = float(r2mag)
            imag = line[221:226].strip()
            if imag == '---' :
                imag = 0
            else:
                imag = float(imag)
            
#            print "%10.6f %10.6f %6d %6d %5.2f %5.2f  %5.2f %5.2f %5.2f" % (RAdeg,DEdeg,pmRA,pmDE,b1mag,b2mag,r1mag,r2mag,imag)
#            g.write("%10.6f %10.6f %6d %6d  %5.2f %5.2f %5.2f %5.2f %5.2f\n" % (RAdeg,DEdeg,pmRA,pmDE,b1mag,b2mag,r1mag,r2mag,imag))
            g.write("%10.6f %10.6f %5.2f %5.2f %5.2f %5.2f\n" % (RAdeg,DEdeg,b1mag,b2mag,r1mag,r2mag))
            
usnob1_rawinputdata.close()
g.close()
#print 'done'


        
    

